---
title: "ACCEPT_WoC_LF_Data_Replication"
author: "Joyce Nguy"
date: "2024-12-22"
output: pdf_document
---

#Load libraries
```{r}
library(haven)
library(tidyverse)
library(stargazer)
library(ggplot2)
library(RColorBrewer)
library(sjPlot)
library(scales)
library(questionr)
library(effects)
library(haven)
library(MASS)
library(corrplot)
library(psy)
library(sjPlot)
library(psych)
library(REdaS)
```

#Load Data 
```{r}
cmps <- read.csv("cmps.csv")
```

#Cleaning Data: Demographic Covariates
```{r}
## Gender, Age, Education, Income, Religious Attendance, Nativity
#Gender
table(cmps$S3b)
cmps$woman <- NA
cmps$woman <- as.numeric(cmps$woman)
cmps$woman <- ifelse(cmps$S3b==2,1,0)
table(cmps$woman)

#Age Categories
table(cmps$S5_Age)
cmps$age <- NA
cmps$age <- as.numeric(cmps$age)
cmps$age[cmps$S5_Age==2] <- 0
cmps$age[cmps$S5_Age==3] <- 0.2
cmps$age[cmps$S5_Age==4] <- 0.4
cmps$age[cmps$S5_Age==5] <- 0.6
cmps$age[cmps$S5_Age==6] <- 0.8
cmps$age[cmps$S5_Age==7] <- 1
table(cmps$age)

#Education
table(cmps$S13)
cmps$education <- NA
cmps$education <- as.numeric(cmps$education)
cmps$education[cmps$S13==1] <- 0
cmps$education[cmps$S13==2] <- 0.167
cmps$education[cmps$S13==3] <- 0.333
cmps$education[cmps$S13==4] <- 0.5
cmps$education[cmps$S13==5] <- 0.667
cmps$education[cmps$S13==6] <- 0.833
cmps$education[cmps$S13==7] <- 1
table(cmps$education)

#Income
table(cmps$Q813)
cmps$income <- NA
cmps$income <- as.numeric(cmps$income)
cmps$income[cmps$Q813==1] <- 0
cmps$income[cmps$Q813==2] <- 0.091
cmps$income[cmps$Q813==3] <- 0.182
cmps$income[cmps$Q813==4] <- 0.273
cmps$income[cmps$Q813==5] <- 0.364
cmps$income[cmps$Q813==6] <- 0.455
cmps$income[cmps$Q813==7] <- 0.545
cmps$income[cmps$Q813==8] <- 0.636
cmps$income[cmps$Q813==9] <- 0.727
cmps$income[cmps$Q813==10] <- 0.818
cmps$income[cmps$Q813==11] <- 0.909
cmps$income[cmps$Q813==12] <- 1
cmps$income[cmps$Q813==99] <- NA
table(cmps$income)  

#Religious Attendance
cmps$religious.attendance <- NA
cmps$religious.attendance <- as.numeric(cmps$religious.attendance)
cmps$religious.attendance[cmps$Q59==1] <- 1
cmps$religious.attendance[cmps$Q59==2] <- 0.8
cmps$religious.attendance[cmps$Q59==3] <- 0.6
cmps$religious.attendance[cmps$Q59==4] <- 0.4
cmps$religious.attendance[cmps$Q59==5] <- 0.2
cmps$religious.attendance[cmps$Q59==6] <- 0
table(cmps$religious.attendance)

#Nativity
table(cmps$S7)
cmps$foreignborn <- NA
cmps$foreignborn <- as.numeric(cmps$foreignborn)
cmps$foreignborn <- ifelse(cmps$S7==2|cmps$S7==3,1,0)
table(cmps$foreignborn)

```

#Cleaning Data: Political Variables
```{r}
#Democratic Party Strength
cmps$democratpartystrength <- NA
cmps$democratpartystrength <- as.numeric(cmps$democratpartystrength)
cmps$democratpartystrength[cmps$Q21==1&cmps$Q22==1] <- 0 
cmps$democratpartystrength[cmps$Q21==1&cmps$Q22==2] <- 0.125   
cmps$democratpartystrength[cmps$Q21==3&cmps$Q23==1] <- 0.25  
cmps$democratpartystrength[cmps$Q21==4&cmps$Q23==1] <- 0.375  
cmps$democratpartystrength[cmps$Q21==3&cmps$Q23==3] <- 0.5 
cmps$democratpartystrength[cmps$Q21==4&cmps$Q23==2] <- 0.625 
cmps$democratpartystrength[cmps$Q21==3&cmps$Q23==2] <- 0.75   
cmps$democratpartystrength[cmps$Q21==2&cmps$Q22==2] <- 0.875  
cmps$democratpartystrength[cmps$Q21==2&cmps$Q22==1] <- 1 
table(cmps$democratpartystrength)



#Interest in politics
cmps$interest <- NA
cmps$interest <- as.numeric(cmps$interest)
cmps$interest[cmps$Q29==1] <- 1
cmps$interest[cmps$Q29==2] <- 0.667
cmps$interest[cmps$Q29==3] <- 0.333
cmps$interest[cmps$Q29==4] <- 0
table(cmps$interest)

#Ideology
cmps$ideology <- NA
cmps$ideology <- as.numeric(cmps$ideology)
cmps$ideology[cmps$Q43==1] <- 1
cmps$ideology[cmps$Q43==2] <- 0.75
cmps$ideology[cmps$Q43==3] <- 0.5
cmps$ideology[cmps$Q43==4] <- 0.25
cmps$ideology[cmps$Q43==5] <- 0
cmps$ideology[cmps$Q43==6] <- NA
table(cmps$ideology)
```

#Cleaning Data: Racial Discrmination 
```{r}
#Perceived Discrimination: Asian
cmps$discrimination.perceived.asian <- NA
cmps$discrimination.perceived.asian <-
  as.numeric(cmps$discrimination.perceived.asian)
cmps$discrimination.perceived.asian[cmps$Q619_Q626r3==1] <- 1
cmps$discrimination.perceived.asian[cmps$Q619_Q626r3==2] <- 0.667
cmps$discrimination.perceived.asian[cmps$Q619_Q626r3==3] <- 0.333
cmps$discrimination.perceived.asian[cmps$Q619_Q626r3==4] <- 0
cmps$discrimination.perceived.asian[cmps$Q619_Q626r3==5] <- NA
table(cmps$discrimination.perceived.asian)

#Perceived Discrimination: Black
cmps$discrimination.perceived.black <- NA
cmps$discrimination.perceived.black <- as.numeric(cmps$discrimination.perceived.black)
cmps$discrimination.perceived.black[cmps$Q619_Q626r2==1] <- 1
cmps$discrimination.perceived.black[cmps$Q619_Q626r2==2] <- 0.667
cmps$discrimination.perceived.black[cmps$Q619_Q626r2==3] <- 0.333
cmps$discrimination.perceived.black[cmps$Q619_Q626r2==4] <- 0
cmps$discrimination.perceived.black[cmps$Q619_Q626r2==5] <- NA
table(cmps$discrimination.perceived.black)

#Perceived Discrimination: Latino
cmps$discrimination.perceived.latino <- NA
cmps$discrimination.perceived.latino <- as.numeric(cmps$discrimination.perceived.latino)
cmps$discrimination.perceived.latino[cmps$Q619_Q626r6==1] <- 1
cmps$discrimination.perceived.latino[cmps$Q619_Q626r6==2] <- 0.667
cmps$discrimination.perceived.latino[cmps$Q619_Q626r6==3] <- 0.333
cmps$discrimination.perceived.latino[cmps$Q619_Q626r6==4] <- 0
cmps$discrimination.perceived.latino[cmps$Q619_Q626r6==5] <- NA
table(cmps$discrimination.perceived.latino)

#Experienced Racial Discrimination
table(cmps$Q629r1) 
cmps$discrimination.experienced.re <- NA
cmps$discrimination.experienced.re[cmps$Q629r1==1] <- 1
cmps$discrimination.experienced.re[cmps$Q629r1==0] <- 0
cmps$discrimination.experienced.re[is.na(cmps$Q629r1)] <- 0
cmps$discrimination.experienced.re <- as.numeric(cmps$discrimination.experienced.re)
table(cmps$discrimination.experienced.re)

```

#Cleaning Data: Racial Linked Fate
```{r}
#Asian Linked Fate 
table(cmps$Q551_Q559r5)
cmps$lf.asian <- NA
cmps$lf.asian <- as.numeric(cmps$lf.asian)
cmps$lf.asian[cmps$Q551_Q559r5==1] <- 0
cmps$lf.asian[cmps$Q551_Q559r5==2] <- 0.25
cmps$lf.asian[cmps$Q551_Q559r5==3] <- 0.5
cmps$lf.asian[cmps$Q551_Q559r5==4] <- 0.75
cmps$lf.asian[cmps$Q551_Q559r5==5] <- 1
table(cmps$lf.asian)

#Black linked fate
table(cmps$Q551_Q559r1)
cmps$lf.black<- NA
cmps$lf.black <- as.numeric(cmps$lf.black)
cmps$lf.black[cmps$Q551_Q559r1==1] <- 0
cmps$lf.black[cmps$Q551_Q559r1==2] <- 0.25
cmps$lf.black[cmps$Q551_Q559r1==3] <- 0.5
cmps$lf.black[cmps$Q551_Q559r1==4] <- 0.75
cmps$lf.black[cmps$Q551_Q559r1==5] <- 1
table(cmps$lf.black)

#Latino linked fate
table(cmps$Q551_Q559r2)
cmps$lf.latino <- NA
cmps$lf.latino <- as.numeric(cmps$lf.latino)
cmps$lf.latino[cmps$Q551_Q559r2==1] <- 0
cmps$lf.latino[cmps$Q551_Q559r2==2] <- 0.25
cmps$lf.latino[cmps$Q551_Q559r2==3] <- 0.5
cmps$lf.latino[cmps$Q551_Q559r2==4] <- 0.75
cmps$lf.latino[cmps$Q551_Q559r2==5] <- 1
table(cmps$lf.latino)
```

#Cleaning Data: WoC ID and WoC LF 
```{r}
#WoC ID
table(cmps$Q561)
cmps$woc <- NA 
cmps$woc <- as.numeric(cmps$woc)
cmps$woc <- ifelse(cmps$Q561 ==1,1,0)
table(cmps$woc)

#WoC Linked Fate
cmps$lf.gender.color <- NA
cmps$lf.gender.color <- as.numeric(cmps$lf.gender.color)
cmps$lf.gender.color[cmps$Q551_Q559r9==1] <- 0
cmps$lf.gender.color[cmps$Q551_Q559r9==2] <- 0.25
cmps$lf.gender.color[cmps$Q551_Q559r9==3] <- 0.5
cmps$lf.gender.color[cmps$Q551_Q559r9==4] <- 0.75
cmps$lf.gender.color[cmps$Q551_Q559r9==5] <- 1
table(cmps$lf.gender.color)
```

#Cleaning DV Variables 
```{r}
#women of color congressional candidates (Latinos and Blacks only) - Feeling Thermometer 
table(cmps$Q575_Q581r1)
cmps$woc_candidates <- NA 
cmps$woc_candidates <- scales::rescale(cmps$Q575_Q581r1, to=c(0,1))
table(cmps$woc_candidates)

#Latina Women Congressional Candidates FT 
table(cmps$Q575_Q581r4)
cmps$latina_cand <- NA 
cmps$latina_cand <- scales::rescale(cmps$Q575_Q581r4, to=c(0,1))
table(cmps$latina_cand)

#Black Women Congressional Candidates FT 
table(cmps$Q575_Q581r5)
cmps$black_cand <- NA 
cmps$black_cand <- scales::rescale(cmps$Q575_Q581r5, to=c(0,1))
table(cmps$black_cand)

#Alexandria Ocasio-Cortez
table(cmps$Q575_Q581r2)
cmps$aoc <- NA 
cmps$aoc <- scales::rescale(cmps$Q575_Q581r2, to=c(0,1))
table(cmps$aoc)

#Ayanna Pressley 
table(cmps$Q575_Q581r7)
cmps$ayanna_pressley <- NA 
cmps$ayanna_pressley <- scales::rescale(cmps$Q575_Q581r7, to=c(0,1))
table(cmps$ayanna_pressley)

#Michelle Obama- Favorability  
table(cmps$Q2r9)
cmps$michelle <- NA
cmps$michelle[cmps$Q2r9==1] <- 1
cmps$michelle[cmps$Q2r9==2] <- 0.75
cmps$michelle[cmps$Q2r9==5] <- 0.5
cmps$michelle[cmps$Q2r9==6] <- 0.5
cmps$michelle[cmps$Q2r9==3] <- 0.25
cmps$michelle[cmps$Q2r9==4] <- 0
table(cmps$michelle)

#Joe Biden Favorability 
table(cmps$Q2r3)
cmps$joe <- NA
cmps$joe[cmps$Q2r3==1] <- 1
cmps$joe[cmps$Q2r3==2] <- 0.75
cmps$joe[cmps$Q2r3==5] <- 0.5
cmps$joe[cmps$Q2r3==6] <- 0.5
cmps$joe[cmps$Q2r3==3] <- 0.25
cmps$joe[cmps$Q2r3==4] <- 0
table(cmps$joe)

#Kamala Harris favorability
table(cmps$Q2r4)
cmps$harris <- NA
cmps$harris[cmps$Q2r4==1] <- 1
cmps$harris[cmps$Q2r4==2] <- 0.75
cmps$harris[cmps$Q2r4==5] <- 0.5
cmps$harris[cmps$Q2r4==6] <- 0.5
cmps$harris[cmps$Q2r4==3] <- 0.25
cmps$harris[cmps$Q2r4==4] <- 0
table(cmps$harris)

```

#Subsetting Data to Race and Gender Group

```{r}
latino <- subset(cmps, subset=(S2_Racer2==1)) # 
latino.women <- subset(latino, subset=(woman==1)) # 

black <- subset(cmps, subset=(S2_Racer3==1)) #
black.women <- subset(black, subset=(woman==1)) #

asian <- subset(cmps, subset=(S2_Racer4==1)) #
asian.women <- subset(asian, subset=(woman==1)) #

```


#Calculating Weighted Means: Identifying as WoC
```{r}
#% Asian WoC ID
addmargins(prop.table(wtd.table(asian.women$woc, weights = asian.women$weight)))
wtd.mean(asian.women$woc, weights=asian.women$weight, na.rm=TRUE) #.585
#% Black WoC ID
addmargins(prop.table(wtd.table(black.women$woc, weights = black.women$weight)))
wtd.mean(black.women$woc, weights=black.women$weight, na.rm=TRUE) #.913
#% Latino WoC ID
addmargins(prop.table(wtd.table(latino.women$woc, weights = latino.women$weight)))
wtd.mean(latino.women$woc, weights=latino.women$weight, na.rm=TRUE) #.379
```




#Calculating Weighted Means: Racial Linked Fate 
```{r}
## Asian 
addmargins(prop.table(wtd.table(asian.women$lf.gender.color, weights = asian.women$weight)))
wtd.mean(asian.women$lf.gender.color, weights=asian.women$weight, na.rm=TRUE) #.527
## Black 
addmargins(prop.table(wtd.table(black.women$lf.gender.color, weights = black.women$weight)))
wtd.mean(black.women$lf.gender.color, weights=black.women$weight, na.rm=TRUE) #.656
## Latino
addmargins(prop.table(wtd.table(latino.women$lf.gender.color, weights = latino.women$weight)))
wtd.mean(latino.women$lf.gender.color, weights=latino.women$weight, na.rm=TRUE) #.467
```


#Figures 1 and 2: Descriptive Statistics
```{r}
color_palette <- c("Asian Women" = "lightgrey", "Black Women" = "darkgray", "Latina Women" = "black")

#WoC ID Levels Across WoC 
woc_data <- data.frame(
  Race = c("Asian Women", "Black Women", "Latina Women"),
  Mean = c(0.59, 0.91, 0.38)
)

woc_chart <- ggplot(woc_data, aes(x = Race, y = Mean, fill = Race)) +
  geom_bar(stat = "identity") +
  geom_text(aes(label = sprintf("%.2f", Mean), y = Mean), 
            vjust = -0.5, color = "black", size = 3) +  # Add the text labels with the Mean values
  scale_fill_manual(values = color_palette) +
  labs(x = "Racial Group", y = "Proportion") +
  ggtitle("Figure 1: Proportion of Women Who Identify As Women of Color")   + 
   scale_y_continuous(limits = c(0, 1)) +  # Set the y-axis limits from 0 to 1 
  theme_minimal() +
  theme(
    panel.background = element_blank(),
    plot.background = element_blank(),  # Remove the background color
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    axis.line = element_line(size = 0.5, color = "black"),
    axis.text = element_text(color = "black"),
    axis.title = element_text(color = "black"),
    plot.title = element_text(hjust = 0.5), 
    legend.position = "none"
  )

#Figure 1
print(woc_chart)

#WoC LF Across Women of Color 
women_lf_data <- data.frame(
  Race = c("Asian Women", "Black Women", "Latina Women"),
  Mean = c(0.53, 0.66, 0.47)
)

women_of_color_chart<- ggplot(women_lf_data, aes(x = Race, y = Mean, fill = Race)) +
  geom_bar(stat = "identity") +
  geom_text(aes(label = sprintf("%.2f", Mean), y = Mean), 
            vjust = -0.05, color = "black", size = 3) +  # Adjust vjust for text label position
  scale_fill_manual(values = color_palette) +
  labs(x = "Racial Group", y = "Proportion") +
  ggtitle("Figure 2: Perceptions of WoC Intersectional Linked Fate \nDisaggregated Across Women of Color") + 
  scale_y_continuous(limits = c(0, 1)) +  # Set the y-axis limits from 0 to 1
  theme_minimal() +
  theme(
    panel.background = element_blank(),
    plot.background = element_blank(),  # Remove the background color
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    axis.line = element_line(size = 0.5, color = "black"),
    axis.text = element_text(color = "black"),
    axis.title = element_text(color = "black"),
    plot.title = element_text(hjust = 0.5), 
    legend.position = "none"
  )

#Figure 2
print(women_of_color_chart)

```

###Main Manuscript Models ###

#Table 1: Ayanna Pressley Favorability 

```{r}

# Original dataset
nrow(cmps)

# Subset for Black women
nrow(black)
nrow(black.women)

# Subset for Latina women
nrow(latino)
nrow(latino.women)

# Model frame (for final sample size)
nrow(model.frame(mod1))


#Latinas: Simple Model
mod1 <- lm(ayanna_pressley~lf.gender.color+ age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ideology+
              discrimination.perceived.latino+discrimination.experienced.re,data=latino.women, weights=latino.women$weight)
summary(mod1)

#Latinas: Full Model 
mod2 <- lm(ayanna_pressley~ lf.gender.color + woc + lf.latino + age+education+income+foreignborn+religious.attendance +
              interest+democratpartystrength+ideology+
              discrimination.perceived.latino+discrimination.experienced.re,data=latino.women, weights=latino.women$weight)
summary(mod2)

#Black Women: Simple Model 
mod3 <- lm(ayanna_pressley~lf.gender.color+ age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ ideology + 
              discrimination.perceived.black+discrimination.experienced.re,data=black.women, weights=black.women$weight)
summary(mod3)

#Black Women: Full Model
mod4 <- lm(ayanna_pressley~lf.gender.color+ woc + lf.black + age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ ideology + 
              discrimination.perceived.black+discrimination.experienced.re,data=black.women, weights=black.women$weight)
summary(mod4)

stargazer(mod3, mod4, mod1, mod2,
          title = "WoC LF and Ayanna Pressley Favorability Among Women of Color",
          type = "text",            
        out = "ayanna_table_1_woc_final.html",  
          digits = 3,              
          dep.var.labels = c("Ayanna Pressley Favorability"),
           column.labels = c("Black Women", "Latinas", "", ""),
          column.separate = c(2, 2), 
          covariate.labels = c("WoC Linked Fate", 
                               "WoC ID", "LF Black",
                              "LF Latino", "Age",
                              "Education", "Income", "Foreign Born",
                              "Religious Attendance", "Political Interest",
                              "Democratic Party Strength", "Ideology", 
                              "Perceived Discrimination", "Experienced Discrimination")
)

```

#Table 2: AoC Favorability 
```{r}
#Latinas: simple model
mod1 <- lm(aoc~lf.gender.color+ age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ideology+
              discrimination.perceived.latino+discrimination.experienced.re,data=latino.women, weights=latino.women$weight)
summary(mod1)

#Latinas: full model
mod2 <- lm(aoc~ lf.gender.color + woc + lf.latino + age+education+income+foreignborn+religious.attendance +
              interest+democratpartystrength+ideology+
              discrimination.perceived.latino+discrimination.experienced.re,data=latino.women, weights=latino.women$weight)
summary(mod2)

#Black women: simple model
mod3 <- lm(aoc~lf.gender.color+ age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ ideology + 
              discrimination.perceived.black+discrimination.experienced.re,data=black.women, weights=black.women$weight)
summary(mod3)

#Black women: full model 
mod4 <- lm(aoc~lf.gender.color+ woc + lf.black + age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ ideology + 
              discrimination.perceived.black+discrimination.experienced.re,data=black.women, weights=black.women$weight)
summary(mod4)

stargazer(mod3, mod4, mod1, mod2,
          title = "WoC LF and AOC Favorability Among Women of Color",
          type = "text",            
          out = "aoc_table_2_woc_final.html",  
          digits = 3,               
          dep.var.labels = c("AoC Favorability"),
          column.labels = c("Black Women", "Latinas", "", ""), 
          column.separate = c(2, 2),  
          covariate.labels = c("WoC Linked Fate", 
                               "WoC ID", "LF Black",
                               "LF Latino", "Age",
                               "Education", "Income", "Foreign Born",
                               "Religious Attendance", "Political Interest",
                               "Democratic Party Strength", "Ideology", 
                               "Perceived Discrimination", "Experienced Discrimination")
)

```

#Figure 3: Predicted Probability Graphs: Black Women and Pressley
```{r}
library(effects)
#Black women for Ayanna
mod1 <- lm(ayanna_pressley~lf.gender.color+ age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ ideology + 
              discrimination.perceived.black+discrimination.experienced.re,data=black.women, weights=black.women$weight)
summary(mod1)

## get predicted probabilities
# Get predicted effects or marginal effects for all predictors
get_model_data(mod1, type="eff", terms = "lf.gender.color")

#Create the dataframe
ayanna_graph <- data.frame(
  lf.gender.color = c(0, 0.25, 0.5, 0.75, 1),
  lf.gender.color.num = c(1, 2, 3, 4, 5),
  range = c(0, 0.2, 0.35, 0.4, 0.66),
  upp.pred.fav = c(0.34, 0.36, 0.38, 0.41, 0.44),
  pred.fav = c(0.31, 0.34, 0.37, 0.40, 0.43),
  low.pred.fav = c(0.28, 0.32, 0.35, 0.38, 0.41)
)

# X axis labels
labels <- c("Low LF", "", "", "", "High LF")

ggplot(ayanna_graph, aes(x = lf.gender.color.num, y = pred.fav)) +
  geom_line(color = "black", size = 1) +
  geom_ribbon(aes(ymin = low.pred.fav, ymax = upp.pred.fav), fill = "grey", alpha = 0.3) +
  labs(x = "WoC Linked Fate", y = "P(Pressley Favorability)",  
       title = "Figure 3: Predicted Probability of Support for Ayanna Pressley \nby WoC Intersectional Linked Fate Among Black Women") +
  scale_y_continuous(limits = c(0.2, 0.5), breaks = seq(0.2, 0.5, 0.1)) +
  scale_x_continuous(breaks = ayanna_graph$lf.gender.color.num, labels = labels, limits = c(1, 5)) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),  # Center the plot title
    panel.grid.major = element_line(color = "gray", linetype = "dashed"),  # Add major grid lines
    panel.grid.minor = element_blank(),  # Remove minor grid lines
    axis.line = element_line(color = "black")  # Add back the x-axis line
  )

```

#Figure 4: Predicted Probability Graphs: Latinas and Pressley 

```{r}
#Run the model 
mod1 <- lm(ayanna_pressley~lf.gender.color+ age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ideology+
              discrimination.perceived.latino+discrimination.experienced.re,data=latino.women, weights=latino.women$weight)
summary(mod1)

## get predicted probabilities
get_model_data(mod1, type="eff", terms = "lf.gender.color")

#Create the dataframe
ayanna_graph <- data.frame(
  lf.gender.color = c(0, 0.25, 0.5, 0.75, 1),
  lf.gender.color.num = c(1, 2, 3, 4, 5),
  range = c(0, 0.2, 0.35, 0.4, 0.66),
  upp.pred.fav = c(0.31, 0.33, 0.34, 0.36, 0.39),
  pred.fav = c(0.29, 0.31, 0.33, 0.35, 0.37),
  low.pred.fav = c(0.27, 0.29, 0.32, 0.33, 0.35)
)

# X axis labels
labels <- c("Low LF", "", "", "", "High LF")

ggplot(ayanna_graph, aes(x = lf.gender.color.num, y = pred.fav)) +
  geom_line(color = "black", size = 1) +
  geom_ribbon(aes(ymin = low.pred.fav, ymax = upp.pred.fav), fill = "grey", alpha = 0.3) +
  labs(x = "WoC Linked Fate", y = "P(Pressley Favorability)",  
       title = "Figure 4: Predicted Probability of Support for Ayanna Pressley \nby WoC Intersectional Linked Fate Among Latinas") +
  scale_y_continuous(limits = c(0.2, 0.5), breaks = seq(0.2, 0.5, 0.1)) +
  scale_x_continuous(breaks = ayanna_graph$lf.gender.color.num, labels = labels, limits = c(1, 5)) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),  # Center the plot title
    panel.grid.major = element_line(color = "gray", linetype = "dashed"),  # Add major grid lines
    panel.grid.minor = element_blank(),  # Remove minor grid lines
    axis.line = element_line(color = "black")  # Add back the x-axis line
  )

```


#Figure 5: Predicted Probability Graphs: Black Women and AoC 
```{r}
mod1 <- lm(aoc~lf.gender.color+ age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ideology+
              discrimination.perceived.black+discrimination.experienced.re,data=black.women, weights=black.women$weight)


## get predicted probabilities
get_model_data(mod1, type="eff", terms = "lf.gender.color")

#Create the dataframe
aoc_graph <- data.frame(
  lf.gender.color = c(0, 0.25, 0.5, 0.75, 1),
  lf.gender.color.num = c(1, 2, 3, 4, 5),
  range = c(0, 0.2, 0.35, 0.4, 0.66),
  upp.pred.fav = c(0.38, 0.41, 0.45, 0.49, 0.54),
  pred.fav = c(0.35, 0.39, 0.43, 0.47, 0.52),
  low.pred.fav = c(0.32, 0.37, 0.42, 0.46, 0.50)
)

# X axis labels
labels <- c("Low LF", "", "", "", "High LF")

ggplot(aoc_graph, aes(x = lf.gender.color.num, y = pred.fav)) +
  geom_line(color = "black", size = 1) +
  geom_ribbon(aes(ymin = low.pred.fav, ymax = upp.pred.fav), fill = "grey", alpha = 0.3) +
  labs(x = "WoC Linked Fate", y = "P(AoC Favorability)",  title = "Figure 5: Predicted Probability of Support for Alexandria Ocasio-Cortez \nby WoC Intersectional Linked Fate Among Black Women") +
  scale_y_continuous(limits = c(.2, 0.6), breaks = seq(0, 0.5, 0.1)) +
  scale_x_continuous(breaks = aoc_graph$lf.gender.color.num, labels = labels, limits = c(1, 5)) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),  # Center the plot title
    panel.grid.major = element_line(color = "gray", linetype = "dashed"),  # Add major grid lines
    panel.grid.minor = element_blank(),  # Remove minor grid lines
    axis.line = element_line(color = "black")  # Add back the x-axis line
  )
```


#Figure 6: Predicted Probability Graphs: Latinas and AoC 
```{r}
mod1 <- lm(aoc~lf.gender.color+ age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ideology+
              discrimination.perceived.latino+discrimination.experienced.re,data=latino.women, weights=latino.women$weight)


## get predicted probabilities
get_model_data(mod1, type="eff", terms = "lf.gender.color")

#Create the dataframe
aoc_graph <- data.frame(
  lf.gender.color = c(0, 0.25, 0.5, 0.75, 1),
  lf.gender.color.num = c(1, 2, 3, 4, 5),
  range = c(0, 0.2, 0.35, 0.4, 0.66),
  upp.pred.fav = c(0.38, 0.42, 0.46, 0.50, 0.55),
  pred.fav = c(0.36, 0.40, 0.44, 0.49, 0.53),
  low.pred.fav = c(0.33, 0.38, 0.43, 0.47, 0.51)
)

# X axis labels
labels <- c("Low LF", "", "", "", "High LF")

ggplot(aoc_graph, aes(x = lf.gender.color.num, y = pred.fav)) +
  geom_line(color = "black", size = 1) +
  geom_ribbon(aes(ymin = low.pred.fav, ymax = upp.pred.fav), fill = "grey", alpha = 0.3) +
  labs(x = "WoC Linked Fate", y = "P(AoC Favorability)",  title = "Figure 6: Predicted Probability of Support for Alexandria Ocasio-Cortez \nby WoC Intersectional Linked Fate Among Latinas") +
  scale_y_continuous(limits = c(.2, 0.6), breaks = seq(0, 0.5, 0.1)) +
  scale_x_continuous(breaks = aoc_graph$lf.gender.color.num, labels = labels, limits = c(1, 5)) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5),  # Center the plot title
    panel.grid.major = element_line(color = "gray", linetype = "dashed"),  # Add major grid lines
    panel.grid.minor = element_blank(),  # Remove minor grid lines
    axis.line = element_line(color = "black")  # Add back the x-axis line
  )

```

#Table 3: Michelle Obama Favorability Amongst Asian Women
```{r}
mod5 <- lm(michelle~lf.gender.color+ age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ ideology + 
              discrimination.perceived.asian+discrimination.experienced.re,data=asian.women, weights=asian.women$weight)
summary(mod5)

mod6 <- lm(michelle~lf.gender.color+ woc + lf.asian + age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ ideology + 
              discrimination.perceived.asian+discrimination.experienced.re,data=asian.women, weights=asian.women$weight)
summary(mod6)

stargazer(mod5, mod6, 
          title = "WoC LF and Michelle Obama Favorability Among Asian Women",
          type = "text",            
          out = "michelle_table_3_woc_final.html",  
          digits = 3,               
          dep.var.labels = c("Michelle Obama Favorability"),
          column.labels = c("Asian Women"),
         # column.separate = c(2, 2, 2),  # Separate the columns into three groups
          covariate.labels = c("WoC Linked Fate", 
                               "WoC ID", "LF Asian", "Age",
                               "Education", "Income", "Foreign Born",
                               "Religious Attendance", "Political Interest",
                               "Democratic Party Strength", "Ideology", 
                               "Perceived Discrimination", "Experienced Discrimination")
)
```

#Table 4: Robustness Check: Joe Biden Favorability Amongst WoC 
```{r}
mod1 <- lm(joe~ lf.gender.color +
            woc + lf.black + age+education+income+foreignborn+religious.attendance +
              interest+democratpartystrength+ideology+
              discrimination.perceived.black+discrimination.experienced.re,data=black.women, weights=black.women$weight)
summary(mod1)


mod2 <- lm(joe~ lf.gender.color + woc + lf.latino + age+education+income+foreignborn+religious.attendance +
              interest+democratpartystrength+ideology+
              discrimination.perceived.latino+discrimination.experienced.re,data=latino.women, weights=latino.women$weight)
summary(mod2)

mod3 <- lm(joe~ lf.gender.color + woc + lf.asian + age+education+income+foreignborn+religious.attendance +
              interest+democratpartystrength+ideology+
              discrimination.perceived.asian+discrimination.experienced.re,data=asian.women, weights=asian.women$weight)
summary(mod3)

stargazer(mod1, mod2, mod3, 
          title = "Table 4: WoC LF and Joe Biden Favorability Among Women of Color",
          type = "text",           
          out = "app_table9_woc_final.html", 
          digits = 3,              
          dep.var.labels = c("Biden Favorability"),
          column.labels = c("Black Women", "Latinas", "Asian Women"),
          covariate.labels = c("WoC Linked Fate", 
                               "WoC ID", "LF Black",
                               "LF Latino", "LF Asian", "Age",
                               "Education", "Income", "Foreign Born",
                               "Religious Attendance", "Political Interest",
                               "Democratic Party Strength", "Ideology", 
                               "Perceived Discrimination", "Experienced Discrimination")
)
```


##Supplementary Materials Tables##

#Supplementary Materials Table C1: WoC LF and Support for Hypothetical WoC Candidates
```{r}
mod1 <- lm(woc_candidates~lf.gender.color+ age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ideology+ 
              discrimination.perceived.black+discrimination.experienced.re,data=black.women, weights=black.women$weight)
summary(mod1)

mod2 <- lm(woc_candidates~ lf.gender.color + woc+ lf.black +  age+education+income+foreignborn+religious.attendance +
              interest+democratpartystrength+ideology+ 
              discrimination.perceived.black+discrimination.experienced.re,data=black.women, weights=black.women$weight)
summary(mod2)

mod3 <- lm(woc_candidates~lf.gender.color+ age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ ideology+ 
              discrimination.perceived.latino+discrimination.experienced.re,data=latino.women, weights=latino.women$weight)
summary(mod3)

#woc, race, gender lf + woc identity 
mod4 <- lm(woc_candidates~ lf.gender.color + woc+lf.latino  + age+education+income+foreignborn+religious.attendance +
              interest+democratpartystrength+ideology+ 
              discrimination.perceived.latino+discrimination.experienced.re,data=latino.women, weights=latino.women$weight)
summary(mod4)


stargazer(mod1, mod2, mod3, mod4,
          title = "Supplementary Materials Table C1: WoC LF and Support for Hypothetical WoC Candidates",
          type = "text",            
          out = "app_table1_woc_final.html",  
          digits = 3,               
          dep.var.labels = c("WoC Candidate Favorability"),
          column.labels = c("Black Women", "Latinas", "", ""),  # Include both Black Women and Latinas in the headers
          column.separate = c(2, 2),  
          covariate.labels = c("WoC Linked Fate", 
                               "WoC ID", "LF Black",
                               "LF Latino", "Age",
                               "Education", "Income", "Foreign Born",
                               "Religious Attendance", "Political Interest",
                               "Democratic Party Strength", "Ideology", 
                               "Perceived Discrimination", "Experienced Discrimination")
)
```

#Supplementary Materials Table C2: WoC lf and Support for a Hypothetical Black Women Congressional Candidate 
```{r}
mod1 <- lm(black_cand~lf.gender.color+ age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ideology+ 
              discrimination.perceived.black+discrimination.experienced.re,data=black.women, weights=black.women$weight)
summary(mod1)

mod2 <- lm(black_cand~ lf.gender.color + woc+ lf.black +  age+education+income+foreignborn+religious.attendance +
              interest+democratpartystrength+ideology+ 
              discrimination.perceived.black+discrimination.experienced.re,data=black.women, weights=black.women$weight)
summary(mod2)

mod3 <- lm(black_cand~lf.gender.color+ age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ ideology+ 
              discrimination.perceived.latino+discrimination.experienced.re,data=latino.women, weights=latino.women$weight)
summary(mod3)

#woc, race, gender lf + woc identity 
mod4 <- lm(black_cand~ lf.gender.color + woc+lf.latino  + age+education+income+foreignborn+religious.attendance +
              interest+democratpartystrength+ideology+ 
              discrimination.perceived.latino+discrimination.experienced.re,data=latino.women, weights=latino.women$weight)
summary(mod4)


stargazer(mod1, mod2, mod3, mod4,
          title = "Supplementary Materials Table C2: WoC LF and Support for Hypothetical Black Women Candidates",
          type = "text",            
          out = "app_table2_woc_final.html",  
          digits = 3,               
          dep.var.labels = c("Black Woman Candidate Favorability"),
          column.labels = c("Black Women", "Latinas", "", ""),  # Include both Black Women and Latinas in the headers
          column.separate = c(2, 2),  
          covariate.labels = c("WoC Linked Fate", 
                               "WoC ID", "LF Black",
                               "LF Latino", "Age",
                               "Education", "Income", "Foreign Born",
                               "Religious Attendance", "Political Interest",
                               "Democratic Party Strength", "Ideology", 
                               "Perceived Discrimination", "Experienced Discrimination")
)
```

#Supplementary Materials Table C3: WoC LF and Support for a Hypothetical Latina Congressional Candidate
```{r}
mod1 <- lm(latina_cand~lf.gender.color+ age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ideology+ 
              discrimination.perceived.black+discrimination.experienced.re,data=black.women, weights=black.women$weight)
summary(mod1)

mod2 <- lm(latina_cand~ lf.gender.color + woc+ lf.black +  age+education+income+foreignborn+religious.attendance +
              interest+democratpartystrength+ideology+ 
              discrimination.perceived.black+discrimination.experienced.re,data=black.women, weights=black.women$weight)
summary(mod2)

mod3 <- lm(latina_cand~lf.gender.color+ age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ ideology+ 
              discrimination.perceived.latino+discrimination.experienced.re,data=latino.women, weights=latino.women$weight)
summary(mod3)

#woc, race, gender lf + woc identity 
mod4 <- lm(latina_cand~ lf.gender.color + woc+lf.latino  + age+education+income+foreignborn+religious.attendance +
              interest+democratpartystrength+ideology+ 
              discrimination.perceived.latino+discrimination.experienced.re,data=latino.women, weights=latino.women$weight)
summary(mod4)


stargazer(mod1, mod2, mod3, mod4,
          title = "Supplementary Materials Table C3: WoC LF and Support for Hypothetical Latina Candidates",
          type = "text",            
          out = "app_table3_woc_final.html",  
          digits = 3,               
          dep.var.labels = c("Latina Candidate Favorability"),
          column.labels = c("Black Women", "Latinas", "", ""),  # Include both Black Women and Latinas in the headers
          column.separate = c(2, 2),  
          covariate.labels = c("WoC Linked Fate", 
                               "WoC ID", "LF Black",
                               "LF Latino", "Age",
                               "Education", "Income", "Foreign Born",
                               "Religious Attendance", "Political Interest",
                               "Democratic Party Strength", "Ideology", 
                               "Perceived Discrimination", "Experienced Discrimination")
)
```

#Supplementary Materials Table D5: WoC LF and Kamala Harris Favorability Among Women of Color
```{r}
#Black women: full model 
mod1 <- lm(harris~lf.gender.color+ woc + lf.black + age+education+income+foreignborn+religious.attendance+
              interest+democratpartystrength+ ideology + 
              discrimination.perceived.black+discrimination.experienced.re,data=black.women, weights=black.women$weight)
summary(mod4)

#Latinas: full model
mod2 <- lm(harris~ lf.gender.color + woc + lf.latino + age+education+income+foreignborn+religious.attendance +
              interest+democratpartystrength+ideology+
              discrimination.perceived.latino+discrimination.experienced.re,data=latino.women, weights=latino.women$weight)
summary(mod2)


#Asian Women 
mod3 <- lm(harris~ lf.gender.color + woc + lf.asian + age+education+income+foreignborn+religious.attendance +
              interest+democratpartystrength+ideology+
              discrimination.perceived.asian+discrimination.experienced.re,data=asian.women, weights=asian.women$weight)
summary(mod3)


stargazer(mod1, mod2, mod3, 
          title = "Supplementary Materials Table D5: WoC LF and Support for Kamala Harris",
          type = "text",  
          out = "app_table7_woc_final.html",
          digits = 3,             
          dep.var.labels = c("Kamala Harris Favorability"),
          column.labels = c("Black Women", "Latinas", "Asian Women"),
          covariate.labels = c("WoC Linked Fate", 
                               "WoC ID", "LF Black",
                               "LF Latino", "LF Asian", "Age",
                               "Education", "Income", "Foreign Born",
                               "Religious Attendance", "Political Interest",
                               "Democratic Party Strength", "Ideology", 
                               "Perceived Discrimination", "Experienced Discrimination")
)

```


#####NBES Data#####

#Read NBES 1996 Data
```{r}
nbes <- read.csv("nbes.csv")
```

#Cleaning Data 
```{r}
#Black women linked fate
nbes$bw_lf <- NA
nbes$bw_lf <- as.numeric(nbes$bw_lf)
nbes$bw_lf[nbes$E8==5] <- 0 
nbes$bw_lf[nbes$E8==8] <- 0.25 
nbes$bw_lf[nbes$E8==9] <- 0.25 
nbes$bw_lf[nbes$E8A==9] <- 0.25 
nbes$bw_lf[nbes$E8A==5] <- 0.5 
nbes$bw_lf[nbes$E8A==3] <- 0.75
nbes$bw_lf[nbes$E8A ==1] <- 1 
table(nbes$bw_lf)

#Black linked fate
table(nbes$QV1)
nbes$lf.black<- NA
nbes$lf.black <- as.numeric(nbes$lf.black)
nbes$lf.black[nbes$QV1==5] <- 0
nbes$lf.black[nbes$QV1A==9] <- .25
nbes$lf.black[nbes$QV1A==8] <- .25
nbes$lf.black[nbes$QV1A==5] <- .5
nbes$lf.black[nbes$QV1A==3] <- .75
nbes$lf.black[nbes$QV1A==1] <- 1
nbes$lf.black[nbes$QV1==8] <- NA
nbes$lf.black[nbes$QV1==9] <- NA
table(nbes$lf.black)

#Carol Moseley Braun
table(nbes$QM1C)
nbes$QM1C <- as.numeric(as.character(nbes$QM1C))
nbes$carol <- nbes$QM1C
nbes$carol <- as.numeric(nbes$carol)
nbes$carol[nbes$QM1C==997] <- NA
nbes$carol[nbes$QM1C==998] <- NA
nbes$carol[nbes$QM1C==999] <- NA
nbes$carol <- scales::rescale(nbes$carol, to=c(0,1))
table(nbes$carol)

#Jesse Jackson 
table(nbes$QM1D)
nbes$QM1D <- as.numeric(as.character(nbes$QM1D))
nbes$jackson <- nbes$QM1D
nbes$jackson <- as.numeric(nbes$jackson)
nbes$jackson[nbes$QM1D==997] <- NA
nbes$jackson[nbes$QM1D==998] <- NA
nbes$jackson[nbes$QM1D==999] <- NA
nbes$jackson <- scales::rescale(nbes$jackson, to=c(0,1))
table(nbes$jackson)

#age 
nbes$age <- nbes$QY1C

#partisanship towards dems 
nbes$democratpartystrength <- NA
nbes$democratpartystrength <- as.numeric(nbes$democratpartystrength)
nbes$democratpartystrength[nbes$QG2==1&nbes$QG2A == 1] <- 0 
nbes$democratpartystrength[nbes$QG2==1&nbes$QG2A == 5] <- 0.125  
nbes$democratpartystrength[nbes$QG2==1&nbes$QG2A == 8] <- 0.25  
nbes$democratpartystrength[nbes$QG2==1&nbes$QG2A == 9] <- 0.25  
nbes$democratpartystrength[nbes$QG2C==1] <- 0.375
nbes$democratpartystrength[nbes$QG2C == 2] <- 0.5 
nbes$democratpartystrength[nbes$QG2C == 8] <- 0.5 
nbes$democratpartystrength[nbes$QG2C == 9] <- 0.5 
nbes$democratpartystrength[nbes$QG2C == 5] <- 0.625 
nbes$democratpartystrength[nbes$QG2 == 5&nbes$QG2B== 8] <- 0.75  
nbes$democratpartystrength[nbes$QG2 == 5&nbes$QG2B== 9] <- 0.75   
nbes$democratpartystrength[nbes$QG2 == 5&nbes$QG2B==5] <- 0.875 
nbes$democratpartystrength[nbes$QG2 == 5&nbes$QG2B==1] <- 1  
table(nbes$democratpartystrength)

#edu level
table(nbes$QY3)
nbes$edu <- NA
nbes$edu <- as.numeric(nbes$edu)
nbes$edu[nbes$QY3==10] <- NA
nbes$edu[nbes$QY3==1] <- 0
nbes$edu[nbes$QY3==2] <- 0.125
nbes$edu[nbes$QY3==3] <- 0.25
nbes$edu[nbes$QY3==4] <- 0.375
nbes$edu[nbes$QY3==5] <- 0.5
nbes$edu[nbes$QY3==6] <- 0.625
nbes$edu[nbes$QY3==7] <- 0.75
nbes$edu[nbes$QY3==8] <- 0.875
nbes$edu[nbes$QY3==9] <- 1
table(nbes$edu)

#income
table(nbes$QY6)
nbes$income <- NA
nbes$income <- as.numeric(nbes$income)
nbes$income[nbes$QY6==1] <- 0
nbes$income[nbes$QY6==2] <- 0.1
nbes$income[nbes$QY6==3] <- 0.2
nbes$income[nbes$QY6==4] <- 0.3
nbes$income[nbes$QY6==5] <- 0.4
nbes$income[nbes$QY6==6] <- 0.5
nbes$income[nbes$QY6==7] <- 0.6
nbes$income[nbes$QY6==8] <- 0.7
nbes$income[nbes$QY6==9] <- 0.8
nbes$income[nbes$QY6==10] <- 0.9
nbes$income[nbes$QY6==11] <- 1
nbes$income[nbes$QY6==98] <- NA
nbes$income[nbes$QY6==99] <- NA
table(nbes$income)  

#political interest 
nbes$interest <- NA
nbes$interest <- as.numeric(nbes$interest)
nbes$interest[nbes$QA1==1] <- 1
nbes$interest[nbes$QA1==3] <- 0.5
nbes$interest[nbes$QA1==5] <- 0
nbes$interest[nbes$QA1==8] <- NA
nbes$interest[nbes$QA1==9] <- NA
table(nbes$interest)

#religion importance
nbes$religion <- NA
nbes$religion <- as.numeric(nbes$religion)
nbes$religion[nbes$QU1==1] <- 1
nbes$religion[nbes$QU1==3] <- 0.5
nbes$religion[nbes$QU1==5] <- 0
nbes$religion[nbes$QU1==8] <- NA
nbes$religion[nbes$QU1==9] <- NA
table(nbes$religion)

```

#Subset Data to Black Women 
```{r}
nbes.black.women <- subset(nbes, subset=(QZ2==2))
```

#Supplementary Materials Table E2: Black Women Linked Fate on Favorability of Carol Moseley Braun and Jesse Jackson Amongst Black Women
```{r}
mod1 <- lm(carol~ bw_lf+ lf.black + age+edu+income+religion+
            interest+democratpartystrength,data=nbes.black.women)
summary(mod1)

mod2 <- lm(jackson~ bw_lf+ lf.black + age+edu+income+religion+
            interest+democratpartystrength,data=nbes.black.women)
summary(mod2)

stargazer(mod1, mod2,
          title = "Supplementary Materials Table E2: Black Women Linked Fate on Favorability of Carol Moseley Braun and Jesse Jackson Amongst Black Women",
          type = "text",           
          out = "app_table10_woc_final.html",  
          dep.var.labels = "Political Figure Favorability Amongst Black Women",
          column.labels = c("Carol Moseley Braun", "Jesse Jackson"),
          covariate.labels = c("Black Woman Linked Fate", 
                               "LF Black",  "Age",
                               "Education", "Income",
                               "Religious Attendance", "Political Interest",
                               "Democratic Party Strength")
)

```





